class GameInfo {

    button : HTMLElement;
    log : HTMLElement;
    orginalText : string;

    constructor(){
        this.button = document.querySelector('#gameInfo button')!;
        this.log = document.querySelector('#gameInfo p')!;
        this.orginalText = this.button.textContent!;
    }

    buttonClick(eventHandle:(this: GlobalEventHandlers, ev: MouseEvent) => any){
        this.button.onclick = eventHandle;
    }

    appendLog(str:string){
        var dat = new Date;//生成日期
        var year = dat.getFullYear();//取得年
        var month = dat.getMonth()+1;    //取得月,js从0开始取,所以+1
        var date1 = dat.getDate(); //取得天
        var hour = dat.getHours();//取得小时
        var minutes = dat.getMinutes();//取得分钟
        var second = dat.getSeconds();//取得秒
        var haomiao = dat.getMilliseconds();
        this.log.innerHTML = `${year}-${month<10?('0' + month):month}-${date1<10?('0' + date1):date1} ${hour<10?'0'+hour:hour}:
                    ${minutes<10?'0'+minutes:minutes}:${second<10?'0'+second:second}.${haomiao<100?(haomiao<10?'00'+haomiao:'0'+haomiao):haomiao} ${str}<br/>${this.log.innerHTML}`;
    }

    reSet(){
        this.button.textContent = this.orginalText;
    }

}

export default GameInfo;